/**
 * http://www.elektronaut.no/articles/2006/06/07/computed-styles
 * 
 * lang.style package
 * 
 * @author Kelemen Viktor kelemen.viktor@gmail.com
 * @version 0.1
 */

YAHOO.namespace('lang.style');

	// makes HTMLElements similar to GFX elements
	
	/**
	 * setFill([r,g,b,a])
	 * setFill({ alpha })
	 */
	HTMLElement.prototype.setFill = function()	{
		
		var arg = arguments[0];
		if (arg.constructor == Array) { 
			if (arg.length<3) { log("setFill argument should be 3 long at least"); return; }
			dojo.style(this, "background", "rgb("+arg[0]+","+arg[1]+","+arg[2]+")");
			
			if (arg[3]!=null)	{
				dojo.style(this, { "opacity": arg[3], "filter": "alpha(opacity="+arg[3]*10+")"} );
				dojo.style(this, "filter", "alpha(opacity="+arg[3]*10+")");
				dojo.style(this, "-moz-opacity", arg[3]);
			}
		} else {
			if (arg.alpha!=null) {
				dojo.style(this, "opacity", arg.alpha);
				dojo.style(this, "filter", "alpha(opacity="+arg.alpha*10+")");
				dojo.style(this, "-moz-opacity", arg.alpha);
			}
		}
		
	}

	/**
	 * setTransform( { dx, dy } );
	 */
	HTMLElement.prototype.setTransform = function()	{
		var arg = arguments[0];

		this.style.position = 'absolute';
		if (arg.dx!=null) this.style.left = arg.dx+'px';
		if (arg.dy!=null) this.style.top = arg.dy+'px';
		
	}
	/*
	deprecated
	YAHOO.lang.style.setAlphaAll = function(alpha)	{
	
		if ((document!=null)&&(document.body!=null))	{
			dojo.forEach(document.body.childNodes, function(e)    {
					if ((e.id!=null)&&((e.id!="livejs_editor")&&(e.id!="livejs_log")) )	{
						Alpha(e,alpha);
					}
			});		
		}
	}
	
	YAHOO.lang.style.fadeAll = function(color,alpha)	{
	
		if ((document!=null)&&(document.body!=null))	{
			dojo.forEach(document.body.childNodes, function(e)    {
				if ((e.nodeType==1))	{
					if ((e.id!=null)&&((e.id!="livejs_editor")&&(e.id!="livejs_log")) )	{
						Alpha(e,alpha);
						setStyle(e,'backgroundColor',color);
					}
				}
			});		
		}
		
	}
	*/